aboutsummaryrefslogtreecommitdiff
path: root/src/app/manga/[title]/[id]/[read]/page.jsx
blob: eaaa94c2ece3ffdfc36ec988a5a89ef8a635dcd5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import styles from "./read.module.css";
import Image from "next/image";
import DownloadManga from "./download";
import CurrentReading from "./currentReading";

export default async function Read({ params }) {
	const chapterId = params.read;
	const data = await getPages(chapterId);
	if (data.length === 0) {
		return (
			<div className={styles.NotFound}>
				<p>
					This chapter has no content. Please check the next chapter.
				</p>
			</div>
		);
	}

	let images = [];
	for (var i = 0; i < data.length; i++) {
		var imgUrl = data[i].img;
		images.push(imgUrl);
	}

	return (
		<div className={styles.Main}>
			<CurrentReading />
			<div className={styles.ImageContainer}>
				<DownloadManga chapterId={chapterId} />
				<p>Total pages: {images.length}</p>
				{images &&
					images.map((item, index) => (
						<div className={styles.Image} key={index}>
							<Image
								src={`https://image-proxy-4xuu.onrender.com/image-proxy?url=${item}`}
								key={index}
								alt="Pages"
								width={800}
								height={1000}
								priority
								unoptimized
							/>
							<p>{index + 1}</p>
						</div>
					))}
			</div>
			<CurrentReading />
		</div>
	);
}

async function getPages(id) {
	const res = await fetch(
		`https://consumet-api-di2e.onrender.com/meta/anilist-manga/read?chapterId=${id}&provider=mangadex`
	);
	const data = await res.json();
	return data;
}